{include file="public/header2" /}

<div class="layuimini-container">
    <form action="{:url('/admin/blog/batchacat')}" method="post">
    <div class="layuimini-main">
        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">用户姓名</label>
                            <div class="layui-input-inline">
                                <input type="text" name="username" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户性别</label>
                            <div class="layui-input-inline">
                                <input type="text" name="sex" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户城市</label>
                            <div class="layui-input-inline">
                                <input type="text" name="city" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <label class="layui-form-label">用户职业</label>
                            <div class="layui-input-inline">
                                <input type="text" name="classify" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>
        <div class="layui-form layui-border-box layui-table-view" lay-filter="LAY-table-1" lay-id="currentTableId" style=" ">
            <div class="layui-table-tool">
                <div class="layui-table-tool-temp">
                    <div class="layui-btn-container">
                        <a href="{:url('/admin/blog/blogcat_add')}" class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </a>
                        <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" onclick="return confirm('确定批量删除吗？');" type="submit" lay-event="delete"> 批量删除 </button> </div>
                </div>
                <div class="layui-table-tool-self">
                    <div class="layui-inline" title="筛选列" lay-event="LAYTABLE_COLS"><i class="layui-icon layui-icon-cols"></i></div>
                    <div class="layui-inline" title="导出" lay-event="LAYTABLE_EXPORT"><i class="layui-icon layui-icon-export"></i></div>
                    <div class="layui-inline" title="打印" lay-event="LAYTABLE_PRINT"><i class="layui-icon layui-icon-print"></i></div>
                    <div class="layui-inline" title="提示" lay-event="LAYTABLE_TIPS"><i class="layui-icon layui-icon-tips"></i></div>
                </div>
            </div>
            <div class="layui-table-body layui-table-main">
                    <table cellspacing="0" cellpadding="0" border="0" class="layui-table" lay-skin="line">
                        <thead>
                        <tr>
                            <th data-field="0" data-key="1-0-0" data-unresize="true" class=" layui-table-col-special">
                    <div class="layui-table-cell laytable-cell-1-0-0 laytable-cell-checkbox">
                        <input type="checkbox" name="layTableCheckbox" lay-skin="primary" lay-filter="layTableAllChoose">
                        <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>
                    </div>
                    </th>
                    <th data-field="id" data-key="1-0-1" class=" layui-unselect">
                        <div class="layui-table-cell laytable-cell-1-0-1"><span>编号</span><span class="layui-table-sort layui-inline"><i class="layui-edge layui-table-sort-asc" title="升序"></i><i class="layui-edge layui-table-sort-desc" title="降序"></i></span></div>
                    </th>
                            <th data-field="username" data-key="1-0-2" class="">
                                <div class="layui-table-cell laytable-cell-1-0-2"><span>标题</span></div>
                            </th>

                    <th data-field="sign" data-key="1-0-5" data-minwidth="150" class="">
                        <div class="layui-table-cell laytable-cell-1-0-5"><span></span></div>
                    </th>
                    <th data-field="10" data-key="1-0-10" data-minwidth="150" class=" layui-table-col-special">
                        <div class="layui-table-cell laytable-cell-1-0-10" align="center"><span>操作</span></div>
                    </th>
                    </tr>
                    </thead>
                    <tbody>
                    {foreach $blogcat as $v}
                    <tr name="a_{$v.category_id}">
                        <td data-field="0" data-key="1-0-0" class="layui-table-col-special">
                            <div class="layui-table-cell laytable-cell-1-0-0 laytable-cell-checkbox">
                                <input type="checkbox" name="id[]" lay-skin="primary" value="{$v.category_id}">
                                <div class="layui-unselect layui-form-checkbox" lay-skin="primary"><i class="layui-icon layui-icon-ok"></i></div>
                            </div>
                        </td>
                        <td data-field="id" data-key="1-0-1" class="">
                            <div class="layui-table-cell laytable-cell-1-0-1">{$a++}</div>
                        </td>
                        <td data-field="username" data-key="1-0-2" class="">
                            <div class="layui-table-cell laytable-cell-1-0-2">{$v.category_name}</div>
                        </td>
                        <td data-field="username" data-key="1-0-2" class="">
                            <div class="layui-table-cell laytable-cell-1-0-2">
                                <img src="/uploads/{$v.path}" alt="" style="height: 50px" />
                            </div>
                        </td>
                        <td data-field="10" data-key="1-0-10" align="center" data-off="true" data-minwidth="150" class="layui-table-col-special">
                            <div class="layui-table-cell laytable-cell-1-0-10">
                                <a href="{:url('/admin/blog/blogcat_edit/cid/'.$v['category_id'])}" class="layui-btn layui-btn-normal layui-btn-sm data-count-edit" lay-event="edit">编辑</a>
                                <a class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn del"  cid="{$v.category_id}" lay-event="delete"> 删除 </a>
                                <button id="delete" style="display: none"></button>
                            </div>
                        </td>
                    </tr>
                    {/foreach}
                    </tbody>
                    </table>
            </div>
        </div>
        <div class="pagination">
            {$blogcat|raw}
        </div>
    </div>
    <script type="text/html" id="currentTableBar">
        <a class="layui-btn layui-btn-normal layui-btn-xs data-count-edit" lay-event="edit">编辑</a>
        <a class="layui-btn layui-btn-xs layui-btn-danger data-count-delete" lay-event="delete">删除</a>
    </script>
</div>
</form>
</div>
<script src="/static/admin/lib/layui-v2.6.3/layui.js" charset="utf-8"></script>
<script>
    layui.use('layer', function(){
        var $ = layui.jquery;
        // 删除操作
        $('a.del').click(function(){
            let cid = $(this).attr('cid');// 获取点击项的id
            //将主键赋值给delete 按钮的属性 blogid
                $('#delete').attr('blogid',cid);
            layer.confirm("确认要删除吗，删除后不能恢复", { title: "删除确认" }, function (index) {
                layer.close(index);
                //点击 detlete 按钮使用 ajax将blogid属性的值（当前需要删除数据的主键）传到PHP控制器
                    //获取当前的 blogid的值
                    var blogid = $('#delete').attr("blogid");
                    //先删除当前的HTML 的 tr
                    //属性选择符
                    $(".layui-table tr[name='a_"+blogid+"']").remove();
                    $.ajax({
                        type: 'get',
                        url:"{:url('/admin/blog/blogcat_del')}",
                        data:'cid='+blogid,
                        dataType: 'text',
                        success: function (z) {
                            console.log(z);
                        }
                    });
                });
            });
    });
</script>
</body>
</html>